package cn.com.ycm.simplefactory;


import cn.com.ycm.entity.Sedan;
import cn.com.ycm.entity.SuvCar;
import cn.com.ycm.entity.VehicleCar;

public class CarCreateFactory {

    public VehicleCar createCar(String param) {
        if ("suv".equals(param)) {
            return new SuvCar();
        } else if ("sedan".equals(param)) {
            return new Sedan();
        } else {
            return null;
        }
    }

    public VehicleCar createCar2(String className) {

        try {
            if (null != className && !"".equals(className)) {
                return (VehicleCar) Class.forName(className).newInstance();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public VehicleCar createCar3(Class clazz) {
       try {
           if (null != clazz) {
               return (VehicleCar)clazz.newInstance();
           }
       }catch (Exception e){
           e.printStackTrace();
       }
       return null;
    }
}
